﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Missile : MonoBehaviour {

    public GameObject BoomOBJ;
    public float MoveSpeed = 10;
    public AudioClip DieAudio;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update ()
    {
        this.transform.Translate(MoveSpeed * Time.deltaTime * Vector3.right);
	}
    //private void OnCollisionEnter2D(Collision2D collision)
    //{
    //    BoxCollider2D box = collision.transform.GetComponent<BoxCollider2D>();
    //    if (box != null)
    //    {
    //        Debug.LogError(box.transform.name);
    //        Debug.LogError(box.gameObject.name);
    //    }
    //}
    //private void OnCollisionStay2D(Collision2D collision)
    //{
        //BoxCollider2D box = Collision.transform.GetComponent<BoxCollider2D>();
        //if (box != null)
        //{
        //    Debug.LogError(box.transform.name);
        //    Debug.LogError(box.gameObject.name);
        //}
    
    //private void OnCollisionExit2D(Collision2D collision)
    //{
        
    //}
    private void OnTriggerEnter2D(Collider2D collision)//停留
    {
        switch (collision.gameObject.tag)
        {
            case "Wall":
                GameObject.Destroy(collision.gameObject);
                GameObject.Destroy(gameObject);
                break;
            case "TieWall":
                GameObject.Destroy(gameObject);
                break;
            case "Enemy":
                GameObject go = GameObject.Instantiate(this.BoomOBJ, collision.transform.position, Quaternion.identity);
                go.transform.localScale = 1.5f * Vector3.one;// new Vector3(3,3,3);
                //GameObject audio = new GameObject();
                AudioSource audio = go.AddComponent<AudioSource>();

                if (audio != null)
                {
                    audio.clip = DieAudio;
                    audio.Play();
                }
                // AudioSource clip =  audio.AddComponent<AudioSource>();
                //clip.
                // go.transform.localPosition = new Vector3(collision.transform.position.x + 10, collision.transform.position.y, collision.transform.position.z);
                GameObject.Destroy(collision.gameObject);
                GameObject.Destroy(gameObject);
                break;
            case "Player":
                break;
            case "Boss":
                break;
        }
    }
    private void OnTriggerExit2D(Collider2D collision)//退出
    {
        
    }
}
